import {
  Entity,
  PrimaryGeneratedColumn,
  OneToMany,
  Column,
  ManyToOne,
  TreeChildren,
  TreeParent,
  Tree
} from 'typeorm';
import { UsersEntity } from '../users/users.entity';


@Entity({ name: 'area' })
@Tree("closure-table")
// @Tree("materialized-path")
// @Tree("nested-set")
export class AreaEntity {
  @PrimaryGeneratedColumn()
  id: number;

  // @Column('int')
  // pid: number;

  @Column('varchar')
  name: string;

  @Column('int')
  type: number;

  @OneToMany(
    () => UsersEntity,
    user => user.province,
  )
  provinceUsers: UsersEntity[];

  @OneToMany(
    () => UsersEntity,
    user => user.city,
  )
  cityUsers: UsersEntity[];

  @TreeChildren()
  children: AreaEntity[];

  @TreeParent()
  parent: AreaEntity;

  // @OneToMany(
  //   type => AreaEntity,
  //   area => area.parent,
  // )
  // children: AreaEntity[];

  // @ManyToOne(
  //   type => AreaEntity,
  //   area => area.children,
  // )
  // parent: AreaEntity;

}
